package com.mdd.front.controller;

import com.mdd.common.aop.NotPower;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.validator.annotation.IDMust;
import com.mdd.front.service.IShopProductService;
import com.mdd.front.validate.shop.ShopProductSearchValidate;
import com.mdd.front.vo.shop.ShopProductDetailVo;
import com.mdd.front.vo.shop.ShopProductListedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/shop")
@Api(tags = "店铺管理")
public class ShopProductController {

    @Resource
    IShopProductService shopProductSetvice;

    @NotPower
    @GetMapping("/all")
    @ApiOperation(value="所有商户")
    public AjaxResult<List<ShopProductListedVo>> all() {
        List<ShopProductListedVo> list = shopProductSetvice.all();
        return AjaxResult.success(list);
    }


    @GetMapping("/list")
    @ApiOperation(value="店铺列表")
    public AjaxResult<List<ShopProductListedVo>> list(@Validated ShopProductSearchValidate searchValidate) {
        List<ShopProductListedVo> list = shopProductSetvice.list(searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="店铺详情")
    public AjaxResult<ShopProductDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        ShopProductDetailVo detail = shopProductSetvice.detail(id);
        return AjaxResult.success(detail);
    }
}
